# -*- coding:utf-8 -*-
"""
describe：login
Author：winni
Email：mwn666888@163.com
Time: 2024/11/29 14:04
Software: PyCharm
"""
from common.ReadYaml import ReadYaml
# from common.commom_requests import Requests
from projectbusinessflows.base_api import BaseApi
from data.user.LoginUsers_UAT import MyData
from common.tools import get_path

class LoginApi(BaseApi):
    def __init__(self,user):
        super().__init__()
        self.url =  f'{self.url}//v1/base/iam/authenticate/login'
        self.method = 'post'
        username =  ReadYaml(get_path("/config/env_uat.yaml")).read()['managerName'][f'{user}']["UserName"]
        password =  ReadYaml(get_path("/config/env_uat.yaml")).read()['managerName'][f'{user}']["Password"]
        # 赋值给登录接口的入参
        self.json = {"identifier": username,
                      "credential": password,
                      "remember": True,
                      "authenticationType": "PASSWORD"}


# def login(user):
#     """
#     封装登录接口
#     :param user: yaml文件里账号密码的用户名称
#     :return:
#     """
#     url = '/v1/base/iam/authenticate/login'
#     # 取出账号密码
#     # username, password = GetConfig().get_username_password(user)
#     username = MyData().userinfo("playwright", f"{user}")["username"]
#     password = MyData().userinfo("playwright", f"{user}")["passwd"]
#     # 赋值给登录接口的入参
#     login_data = {"identifier": username,
#                   "credential": password,
#                   "remember": True,
#                   "authenticationType": "PASSWORD"}
#     # 执行接口请求
#     res = Requests().post_request(url=url,
#                                   json=login_data)
#     return res